<include file="public@header"/>
<style type="text/css">
    .pic-list li {
        margin-bottom: 5px;
    }
    .w-20{width: 20%;float: left}
    .z_zuobiao{float: left;line-height: 34px;height: 34px;margin: 0;}
    .maid{width: 70px;float: left;margin-right: 5px;}
</style>
<script type="text/html" id="photos-item-tpl">
    <li id="saved-image{id}">
        <input id="photo-{id}" type="hidden" name="photo_urls[]" value="{filepath}">
        <input class="form-control" id="photo-{id}-name" type="text" name="photo_names[]" value="{name}"
               style="width: 200px;" title="图片名称">
        <img id="photo-{id}-preview" src="{url}" style="height:36px;width: 36px;"
             onclick="imagePreviewDialog(this.src);">
        <a href="javascript:uploadOneImage('图片上传','#photo-{id}');">替换</a>
        <a href="javascript:(function(){$('#saved-image{id}').remove();})();">移除</a>
    </li>
</script>
<script type="text/html" id="files-item-tpl">
    <li id="saved-file{id}">
        <input id="file-{id}" type="hidden" name="file_urls[]" value="{filepath}">
        <input class="form-control" id="file-{id}-name" type="text" name="file_names[]" value="{name}"
               style="width: 200px;" title="文件名称">
        <a id="file-{id}-preview" href="{preview_url}" target="_blank">下载</a>
        <a href="javascript:uploadOne('文件上传','#file-{id}','file');">替换</a>
        <a href="javascript:(function(){$('#saved-file{id}').remove();})();">移除</a>
    </li>
</script>
</head>
<body>
<div class="wrap js-check-wrap">
    <ul class="nav nav-tabs">
        <li><a href="{:url('admin_store/index')}">店铺管理</a></li>
        <li><a href="{:url('admin_store/add')}">添加店铺</a></li>
        <li class="active"><a href="javascript:;">编辑店铺</a></li>
    </ul>
    <form action="{:url('admin_store/edit')}" method="post" class="form-horizontal js-ajax-form margin-top-20">
        <input type="hidden" name="post[id]" value="{$store_info.id}">
        <div class="row">
            <div class="col-md-2">
                <table class="table table-bordered">
                    <tr>
                        <th>店铺头像</th>
                    </tr>
                    <tr>
                        <td>
                            <div style="text-align: center;">
                                <input type='hidden' name='post[more][thumbnail]' id='thumbnail'
                                       value="{$store_info.more.thumbnail|default=''}">
                                <a href="javascript:uploadOneImage('图片上传','#thumbnail');">
                                    <if condition="empty($store_info['more']['thumbnail'])">
                                        <img src="__TMPL__/public/assets/images/default-thumbnail.png"
                                             id='thumbnail-preview'
                                             width='135' height='135' style='cursor: pointer'/>
                                        <else/>
                                        <img src="{:cmf_get_image_preview_url($store_info['more']['thumbnail'])}"
                                             id='thumbnail-preview'
                                             width='135' height='135' style='cursor: hand'/>
                                    </if>

                                </a>
                                <input type="button" class="btn btn-sm"
                                       onclick="$('#thumbnail-preview').attr('src','__TMPL__/public/assets/images/default-thumbnail.png');$('#thumbnail').val('');return false;"
                                       value="取消图片">
                            </div>
                        </td>
                    </tr>


                </table>
            </div>
            <div class="col-md-10">
                <table class="table table-bordered">
                    <tr>
                        <th width="100">店铺名称<span class="form-required">*</span></th>
                        <td>
                            <input class="form-control" type="text" style="width: 400px;" name="post[store_name]" required  placeholder="请输入店铺名称" value="{$store_info.store_name}"/>
                        </td>
                    </tr>
                    <tr>
                        <th>用户<span class="form-required">*</span></th>
                        <td>
                            <input class="form-control" type="text" style="width:400px;" required value="{$store_info.user.user_login}"   placeholder="请选择绑定用户" onclick="doSelectUser();" id="js-user-name-input"  readonly/>
                            <input class="form-control" type="hidden" value="{$store_info.user.id}" name="post[user_id]" id="js-user-id-input"/>
                        </td>
                    </tr>
                    <tr>
                        <th>负责人电话<span class="form-required">*</span></th>
                        <td>
                            <input class="form-control" type="text" value="{$store_info.phone}" name="post[phone]" />
                        </td>
                    </tr>
                    <tr>
                        <th>店铺地址<span class="form-required">*</span></th>
                        <td>
                            <select name="post[province_id]" id="provice" class="form-control"  style="width: 160px;float: left;" required >
                                <option value="">请选择省</option>
                                <foreach name="Address_list" item="v">
                                    <option value="{$v.province_id}" <eq name="store_info.province_id" value="$v['province_id']">selected</eq>>{$v.province_name}</option>
                                </foreach>
                            </select>
                            <select name="post[city_id]" id="city" class="form-control"  style="width: 160px;float: left;margin-left: 5px;" required>
                                <option value="">请选择市</option>
                                <foreach name="city_list" item="v">
                                    <option value="{$v.city_id}" <eq name="store_info.city_id" value="$v['city_id']">selected</eq>>{$v.city_name}</option>
                                </foreach>
                            </select>
                            <select name="post[district_id]" id="district" class="form-control"  style="width: 160px;float: left;margin-left: 5px;" required>
                                <option value="">请选择区</option>
                                <foreach name="District_list" item="v">
                                    <option value="{$v.district_id}" <eq name="store_info.district_id" value="$v['district_id']">selected</eq>>{$v.district_name}</option>
                                </foreach>
                            </select>
                            <input type="text" name="post[address]" class="form-control" placeholder="请输入详细街道" style="float: left;margin-top: 5px;" required value="{$store_info.address}">
                        </td>
                    </tr>
                    <tr>
                        <th>营业时间<span class="form-required">*</span></th>
                        <td>
                            <input type="text" name="post[time]" class="form-control" placeholder="周一至周日10:00-21:00营业" style="float: left;margin-top: 5px;" required  value="{$store_info.time}">
                        </td>
                    </tr>
                    <tr>
                        <th>坐标<span class="form-required">*</span></th>
                        <td>
                            <p class="z_zuobiao">经度：&nbsp;</p>
                            <input type="text" name="post[lng]" class="lng form-control w-20" readonly required  value="{$store_info.lng}" >
                            <p class="z_zuobiao">&nbsp;纬度：&nbsp;</p>
                            <input type="text" name="post[lat]" class="lat form-control w-20" readonly required   value="{$store_info.lat}">
                            <a href="javascript:;" onclick="doSelectLocation(this)" class="btn btn-success btn-sm" style="height: 34px;line-height: 30px;margin-left: 10px;">选择</a>
                        </td>
                    </tr>
                    <notempty name="store_info['tjuser']">
                    <tr>
                        <th>推荐用户<span class="form-required">*</span></th>
                        <td>
                            <input type="text" value="{$store_info.tjuser.user_login}" readonly class="form-control" style="width: 400px;">

                        </td>
                    </tr>
                    </notempty>
                    <tr>
                        <th>店铺介绍<span class="form-required">*</span></th>
                        <td>
                            <script type="text/plain" id="content" name="post[store_content]">{:htmlspecialchars_decode($store_info.store_content)}</script>
                        </td>
                    </tr>
                    <tr>
                        <th>相册</th>
                        <td>

                            <ul id="photos" class="pic-list list-unstyled form-inline">
                                <notempty name="store_info.more.photos">
                                    <foreach name="store_info.more.photos" item="vo">
                                        <php>$img_url=cmf_get_image_preview_url($vo['url']);</php>
                                        <li id="saved-image{$key}">
                                            <input id="photo-{$key}" type="hidden" name="photo_urls[]"
                                                   value="{$vo.url}">
                                            <input class="form-control" id="photo-{$key}-name" type="text"
                                                   name="photo_names[]"
                                                   value="{$vo.name|default=''}" style="width: 200px;" title="图片名称">
                                            <img id="photo-{$key}-preview"
                                                 src="{:cmf_get_image_preview_url($vo['url'])}"
                                                 style="height:36px;width: 36px;"
                                                 onclick="parent.imagePreviewDialog(this.src);">
                                            <a href="javascript:uploadOneImage('图片上传','#photo-{$key}');">替换</a>
                                            <a href="javascript:(function(){$('#saved-image{$key}').remove();})();">移除</a>
                                        </li>
                                    </foreach>
                                </notempty>
                            </ul>
                            <a href="javascript:uploadMultiImage('图片上传','#photos','photos-item-tpl');"
                               class="btn btn-default btn-sm">选择图片</a>
                        </td>
                    </tr>
                    <tr>
                        <th>返佣<span class="form-required">*</span></th>
                        <td>
                            <input class="form-control maid m_maid" type="number"  value="{$store_info.maid*100}" min="1" step="1" max="100" readonly><p class="z_zuobiao">%</p>
                            <input type="hidden" class="m_rec_maid" name="post[maid]"  value="{$store_info.maid}" readonly/>
                        </td>
                    </tr>
                    <tr>
                        <th>推荐返佣<span class="form-required">*</span></th>
                        <td>
                            <input class="form-control maid rec_maid" type="number"  value="{$store_info.rec_maid*100}" min="1" step="1" max="100" readonly><p class="z_zuobiao">%</p>
                            <input type="hidden"  name="post[rec_maid]" class="h_rec_maid" value="{$store_info.rec_maid}" readonly/>
                        </td>
                    </tr>
                    </tbody>
                </table>
                <div class="form-group">
                    <div class="col-sm-offset-2 col-sm-10">
                        <button type="submit" class="btn btn-primary js-ajax-submit">{:lang('SAVE')}</button>
                        <a class="btn btn-default" href="{:url('admin_store/index')}">{:lang('BACK')}</a>
                    </div>
                </div>
            </div>

        </div>
    </form>
</div>
<script type="text/javascript" src="__STATIC__/js/admin.js"></script>
<script type="text/javascript">
    //编辑器路径定义
    var editorURL = GV.WEB_ROOT;
</script>
<script type="text/javascript" src="__STATIC__/js/ueditor/ueditor.config.js"></script>
<script type="text/javascript" src="__STATIC__/js/ueditor/ueditor.all.min.js"></script>
<script type="text/javascript">
    $(function () {

        editorcontent = new baidu.editor.ui.Editor();
        editorcontent.render('content');
        try {
            editorcontent.sync();
        } catch (err) {
        }

        $('#more-template-select').val('page');
        $('#provice').change(function () {
            var province_id=$(this).val();
            $.ajax({
                type : "post",
                url : "{:url('admin/Sysarea/selectcitylistajax')}",
                data : {"province_id" : province_id},
                success : function(data){
                    var html='';
                    for (var i = 0; i < data.length; i++) {
                        html=html+'<option value="'+data[i]['city_id']+'">'+data[i]['city_name']+'</option>';
                    }
                    $('#city').html(html)
                }
            })
        })
        $('#city').change(function () {
            var city_id=$(this).val();
            $.ajax({
                type : "post",
                url : "{:url('admin/Sysarea/selectdistrictlistajax')}",
                data : {"city_id" : city_id},
                success : function(data){
                    var html='';
                    for (var i = 0; i < data.length; i++) {
                        html=html+'<option value="'+data[i]['district_id']+'">'+data[i]['district_name']+'</option>';
                    }
                    $('#district').html(html)
                }
            })
        })
    });
    function doSelectLocation(obj) {
        var $obj       = $(obj);
        var location   = $('.lng').val()+','+$('.lat').val();
        parent.openIframeLayer(
            "/admin/dialog/map.html?location=" + location,
            '坐标选择',
            {
                area: ['95%', '90%'],
                btn: ['确定', '取消'],
                yes: function (index, layero) {
                    var iframeWin = parent.window[layero.find('iframe')[0]['name']];
                    var location  = iframeWin.confirm();
                    $('.lng').val(location.lng);
                    $('.lat').val(location.lat);
                    parent.layer.close(index); //如果设定了yes回调，需进行手工关闭
                }
            }
        );
    }
    function doSelectUser() {
        var selectedUserId = $('#js-user-id-input').val();
        openIframeLayer("{:url('admin/user/select')}?id=" + selectedUserId, '请选择绑定用户', {
            area: ['700px', '400px'],
            btn: ['确定', '取消'],
            yes: function (index, layero) {
                //do something

                var iframeWin          = window[layero.find('iframe')[0]['name']];
                var selectedUser = iframeWin.confirm();
                if (selectedUser.selectedUserId.length == 0) {
                    layer.msg('请选择用户');
                    return;
                }
                $('#js-user-id-input').val(selectedUser.selectedUserId.join(','));
                $('#js-user-name-input').val(selectedUser.selectedUserName.join(' '));
                //console.log(layer.getFrameIndex(index));
                layer.close(index); //如果设定了yes回调，需进行手工关闭
            }
        });
    }
</script>
</body>
</html>
